<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>滴答办公系统-学员列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="/media/layui/css/layui.css" media="all">
<script src="/media/js/jquery.min.js"></script>
	<script type="text/javascript">
		//页码
		function goPage(pageIndex,pageSize) {
			//提交的地址
			$("#ff").prop("action","/student_list?pageIndex="+pageIndex+"&pageSize=" + pageSize);
			//提交搜索表单(搜索条件)
			$("#ff").submit();
		}

		//修改每页大小
		function changePageSize(pageSize) {
			$("#ff").prop("action","/student_list?pageIndex=1&pageSize=" + pageSize);
			$("#ff").submit();
		}

		//跳转页面
		function jumpPage(pageCount, pageSize) {
			var pageNum = $("#pageNum").val();
			//alert(pageNum);
			var regex = /^[1-9]\d*$/;
			if (regex.test(pageNum) == true) {
				//alert("是一个数字~");
				if (pageNum >= 1 && pageNum <= pageCount) {
					$("#ff").prop("action","/student_list?pageIndex=" + pageNum + "&pageSize=" + pageSize);
					$("#ff").submit();
				} else {
					alert("请输入一个合法的数字!")
				}
			} else {
				alert("请输入一个数字!")
			}
		}
		function student_export() {
			$("#ff").prop("action","/student_exportTo");
			$("#ff").submit();
		}
	</script>
</head>
<body>
<form action="/student_list?pageIndex=1&pageSize=5" method="post" id="ff">
<div class="layui-container">
    <div class="layui-row" style="margin-top: 10px">
        <div class="layui-col-xs3" style="margin-right: 20px">
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">姓名：</label>
                <div class="layui-input-block">
                    <input type="text" id="no" name="name" th:value="${name}" class="layui-input" placeholder="学生姓名">
                </div>
            </div>
        </div>
        <div class="layui-col-xs3" style="margin-right: 20px">
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">班级：</label>
                <div class="layui-input-block">
                    <select class="layui-input" name="class_id" id="fg">
                        <option value="0">全部</option>
<!--                        <option value="1">JAVA1805班</option>-->
<!--                        <option value="2">JAVA1806班</option>-->
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs2">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" type="submit" ><i class="layui-icon layui-icon-search">搜索</i></button>
                </div>
            </div>
        </div>
        <div class="layui-col-xs2">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <a class="layui-btn layui-btn-mini layui-btn-mini" href="javascript:student_export();"
					   lay-event="detail">导出Excel</a>
                </div>
            </div>
        </div>
    </div>
</div>
</form>
	<div class="layui-container">
		<table class="layui-table" id="tbdata" lay-filter="tbop">
			<thead>
				<tr>
					<td>学号</td>
					<td>姓名</td>
					<td>班级</td>
					<td>性别</td>
					<td>QQ</td>
					<td>手机号</td>
					<td>邮箱</td>
					<td>学校</td>
					<td>学历</td>

					<td>操作</td>
				</tr>
			</thead>
			<tbody>
				<tr th:each="d:${PageUtils.records}" >
					<td th:text="${d.id}">01</td>
					<td th:text="${d.name}">老王</td>
					<td th:text="${d.classes.class_Name}">JAVAEE</td>
					<td th:text="${d.sex}">女</td>
					<td th:text="${d.qq}">女</td>
					<td th:text="${d.phone}">1336789100</td>
					<td th:text="${d.email}">1336789100</td>
					<td th:text="${d.school}">1336789100</td>
					<td th:text="${d.education}">23423@qq.com</td>

					<td><a class="layui-btn layui-btn-mini" th:href="|/student_toUpdate/${d.id}|">编辑</a>
						<a class="layui-btn layui-btn-mini layui-btn-mini" th:href="|/studentdetails/${d.id}|" lay-event="detail">查看详情</a>
						<a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del" th:onclick="|deleteCourse(${d.id});|">删除</a>
					</td>
				</tr>

			</tbody>
		</table>
		<div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
			<a th:href="|javascript:goPage(${PageUtils.pageIndex-1},${PageUtils.pageSize})|"
			   th:if="${PageUtils.pageIndex>1}" class="layui-laypage-pre" data-page="0">
				<i class="layui-icon">&lt;</i>
			</a>

			<!--<span style="color:#009688;font-weight: bold;">1</span>-->
			<a th:each="num:${PageUtils.numbers}" th:href="|javascript:goPage(${num},${PageUtils.pageSize})|"
			   th:style="${PageUtils.pageIndex==num}?'color:#009688;font-weight: bold;':''" th:text="${num}">xxxx</a>

			<a th:href="|javascript:goPage(${PageUtils.pageIndex+1},${PageUtils.pageSize})|"
			   th:if="${PageUtils.pageIndex<PageUtils.pageCount}" class="layui-laypage-next" data-page="2">
				<i class="layui-icon">&gt;</i>
			</a>

			<span class="layui-laypage-skip">到第
							    <input type="text" min="1" th:value="${PageUtils.pageIndex}" class="layui-input"
									   id="pageNum">页
								<button type="button" class="layui-laypage-btn"
										th:onclick="|jumpPage(${PageUtils.pageCount},${PageUtils.pageSize});|">确定</button>
							</span>
			<span class="layui-laypage-count">当前[[${PageUtils.pageIndex}]]/[[${PageUtils.pageCount}]]页/[[${PageUtils.totalCount}]]条</span>
			<span class="layui-laypage-limits">
							    <select lay-ignore="" th:onchange="|changePageSize(this.value);|">
							        <option value="5" th:selected="${PageUtils.pageSize==5}">5 条/页</option>
									<option value="10" th:selected="${PageUtils.pageSize==10}">10 条/页</option>
									<option value="15" th:selected="${PageUtils.pageSize==15}">15 条/页</option>
									<option value="20" th:selected="${PageUtils.pageSize==20}">20 条/页</option>
							</select>
							</span>
						</div>
	</div>
	
	<script src="/media/layui/layui.js"></script>
	
	<script type="text/javascript">

		$(function () {
			$.get("/student_findClasses",null,function(arr){
				for(i=0;i<arr.length;i++){
					$("#fg").append("<option value='"+arr[i].id+"'>"+arr[i].class_Name+"</option>");
				}
				//搜索下拉框回显
				$("#fg").val([[${class_id}]]);
			});

		})
	   function deleteCourse(id){
		   layui.use('table', function() {
			   layer.confirm('是否确认删除学生?',function(index) {
			   	$.getJSON("/deleteStudent","id="+id,function (result) {
					if (result==true){
						layer.msg("删除成功", {icon : 6},function () {
							window.location.reload();
						});
					}else {
						layer.msg("删除失败", {icon : 5});
					}
				})


			   });
		   });
	   }
	</script>
	
	
</body>
</html>